<template>
  <section>
    EventsDemo
    <el-button @click="btn1"> 111 </el-button>
    <el-button @click="btn2"> 222 </el-button>
  </section>
</template>

<script>
import EventEmitter from "events";

class eventTest {
  constructor() {
    this._emitter = new EventEmitter();
  }

  on(event, listener) {
    this._emitter.addListener(event, listener);
  }

  off(event, listener) {
    this._emitter.removeListener(event, listener);
  }
}

export default {
  name: "EventsDemo",
  data() {
    return {
      event: new eventTest(),
    };
  },
  mounted() {
    // console.log(events)
    this.event.on("111", (a,b,c) => {
      console.log(111,a,b,c);
    });
  },
  methods: {
    btn1() {
      console.log("btn1");
      this.event._emitter.emit("111",'333','444');
    },
    btn2() {
      console.log("btn2");
      this.event.on("111", (a,b,c) => {
        console.log(222,a,b,c);
      });
    },
  },
};
</script>

<style>
</style>